package ai.connectfour;

import java.util.ArrayList;

import ai.connectfour.entities.Action;
import ai.connectfour.entities.Player;
import ai.connectfour.entities.State;

public class TestMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
//		testCase1();
//		testCaseDiagonalUpperLeftToLowerRight();
//		testCaseDiagonalUpperLeftToLowerRightBorderRight();
//		testCaseDiagonalUpperLeftToLowerRightBorderLeft();
//		testCaseDiagonalUpperLeftToLowerRightUpperBorder();
//		testCaseDiagonaleLowerLeftToUpperRight();
//		testCaseDiagonaleLowerLeftToUpperRightBorderRight();
//		testCaseDiagonaleLowerLeftToUpperRightBorderLeft();
//		testCaseDiagonaleLowerLeftToUpperRightUpperBorder();
//		testCaseDiagonalUpperLeftToLowerRightBorderUpAndLeft();
//		verticalTest();
//		TestError01();
		testCaseVierterWirdNichtGemacht(); // noch falsch
	}
	
	private static void testCaseVierterWirdNichtGemacht() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(4, red));
		
		Action currAction=null;
		
		System.out.println("testCaseVierterWirdNichtGemacht 3:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
		}

		System.out.println(testState.toString() + "\n" + testState.terminalTest());
		System.out.println("testCaseVierterWirdNichtGemacht Ende!\n");
	}

	private static void testCaseDiagonalUpperLeftToLowerRight() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(2, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(2, yellow));
		
		
		Action currAction;
		
		System.out.println("Test 3:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			System.out.println(testState.toString() + "\n" + testState.terminalTest());
		}
		
		System.out.println("Test 3 Ende!\n");
	}
	
	private static void TestError01() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		
		
		Action currAction = null;
		
		System.out.println("Test TestError01:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}

		System.out.println(testState.toString() + "\n" + testState.terminalTest());
//		System.out.println("Test correct: " + testState.terminalTest(currAction) + "\n");
		
		System.out.println("Test TestError01 Ende!\n");
	}
	
	private static void verticalTest() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(0, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(0, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(4, red));
				
		Action currAction = null;
		
		System.out.println("Test verticalTest:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}

		System.out.println(testState.toString() + "\n" + "Test correct: " + testState.terminalTest());
		
		System.out.println("Test verticalTest Ende!\n");
	}
	
	private static void testCaseDiagonalUpperLeftToLowerRightBorderUpAndLeft() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(0, red));
		turnList.add(new Action(1, yellow));
		turnList.add(new Action(1, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(2, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(1, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(1, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(2, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(2, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(0, red));
		turnList.add(new Action(1, yellow));
		turnList.add(new Action(1, red));
		turnList.add(new Action(0, yellow));
		
		
		Action currAction = null;
		
		System.out.println("Test testCaseDiagonalUpperLeftToLowerRightBorderUpAndLeft:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}
		System.out.println("Test correct: " + testState.terminalTest() + "\n");
		
		System.out.println("Test testCaseDiagonalUpperLeftToLowerRightBorderUpAndLeft Ende!\n");
	}
	
	private static void testCaseDiagonalUpperLeftToLowerRightBorderLeft() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(1, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(1, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(2, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(2, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(0, red));
		turnList.add(new Action(1, yellow));
		turnList.add(new Action(1, red));
		turnList.add(new Action(0, yellow));
		
		
		Action currAction = null;
		
		System.out.println("Test BorderLeft:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}
		System.out.println("Test correct: " + testState.terminalTest() + "\n");
		
		System.out.println("Test Borderleft Ende!\n");
	}

	private static void testCaseDiagonalUpperLeftToLowerRightBorderRight() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(6, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(3, yellow));
		
		
		Action currAction = null;
		
		System.out.println("Test Diagonal Upper Left To Lower Right Border Right:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}
		System.out.println("Test correct: " + testState.terminalTest() + "\n");
		
		System.out.println("Test Diagonal Upper Left To Lower Right Border Right Ende!\n");
	}
	
	private static void testCaseDiagonalUpperLeftToLowerRightUpperBorder() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(6, yellow));
		turnList.add(new Action(6, red));
		turnList.add(new Action(6, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(3, yellow));
		
		
		Action currAction = null;
		
		System.out.println("Test DiagonalUpperLeftToLowerRightUpperBorder:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}
		System.out.println("Test correct: " + testState.terminalTest() + "\n");
		
		System.out.println("Test DiagonalUpperLeftToLowerRightUpperBorder Ende!\n");
	}
	
	private static void testCaseDiagonaleLowerLeftToUpperRight() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(5, yellow));

		
		
		Action currAction = null;
		
		System.out.println("Test testCaseDiagonaleLowerLeftToUpperRight:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}
		System.out.println("Test correct: " + testState.terminalTest() + "\n");
		
		System.out.println("Test testCaseDiagonaleLowerLeftToUpperRight Ende!\n");
	}
	
	private static void testCaseDiagonaleLowerLeftToUpperRightBorderLeft() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(1, red));
		turnList.add(new Action(1, yellow));
		turnList.add(new Action(2, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(2, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(0, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(3, yellow));

		
		
		Action currAction = null;
		
		System.out.println("Test testCaseDiagonaleLowerLeftToUpperRightBorderLeft:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}
		System.out.println("Test correct: " + testState.terminalTest() + "\n");
		
		System.out.println("Test testCaseDiagonaleLowerLeftToUpperRightBorderLeft Ende!\n");
	}
	
	private static void testCaseDiagonaleLowerLeftToUpperRightBorderRight() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(6, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(6, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(6, red));
		turnList.add(new Action(6, yellow));

		
		
		Action currAction = null;
		
		System.out.println("Test testCaseDiagonaleLowerLeftToUpperRightBorderRight:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}
		
		System.out.println("Test correct: " + testState.terminalTest() + "\n");
		
		System.out.println("Test testCaseDiagonaleLowerLeftToUpperRightBorderRight!\n");
	}

	private static void testCaseDiagonaleLowerLeftToUpperRightUpperBorder() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;

		State testState = new State();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(3, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(6, yellow));
		turnList.add(new Action(6, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(4, red));
		turnList.add(new Action(4, yellow));
		turnList.add(new Action(5, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(6, red));
		turnList.add(new Action(5, yellow));
		turnList.add(new Action(6, red));
		turnList.add(new Action(3, yellow));
		turnList.add(new Action(6, red));
		turnList.add(new Action(6, yellow));

		
		
		Action currAction = null;
		
		System.out.println("Test testCaseDiagonaleLowerLeftToUpperRightUpperBorder:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			//System.out.println(testState.toString() + "\n" + testState.terminalTest(currAction));
		}
		
		System.out.println("Test correct: " + testState.terminalTest() + "\n");
		
		System.out.println("Test testCaseDiagonaleLowerLeftToUpperRightBorderRight!\n");
	}
	
	
	private static void testCase1() {
		Player currPlayer;
		Player yellow = Player.MIN;
		Player red = Player.MAX;
		
		Action row1Action = new Action(0, yellow);
		Action row2Action = new Action(1, yellow);
		Action row3Action = new Action(2, yellow);
		Action row4Action = new Action(3, yellow);
		Action row5Action = new Action(4, yellow);
		Action row6Action = new Action(5, yellow);
		Action row7Action = new Action(6, yellow);

		State testState = new State();
		
		//row1Action.setPlayer();
		
		ArrayList<Action> turnList = new ArrayList<Action>();
		turnList.add(row5Action);
		turnList.add(row5Action);
		turnList.add(row6Action);
		turnList.add(row5Action);
		turnList.add(row7Action);
		turnList.add(row5Action);
		turnList.add(row3Action);
		
		
		Action currAction;
		
		System.out.println("Test 1:\n");
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			System.out.println(testState.toString() + "\n" + testState.terminalTest());
		}
		
		System.out.println("Test 1 Ende!\n");
		
		System.out.println("Test 2:\n");
		testState = new State();
		
		
		turnList = new ArrayList<Action>();
		turnList.add(row3Action);
		turnList.add(row3Action);
		turnList.add(row4Action);
		turnList.add(row3Action);
		turnList.add(row3Action);
		turnList.add(row4Action);
		turnList.add(row4Action);
		turnList.add(row4Action);
		turnList.add(row5Action);
		turnList.add(row4Action);
		turnList.add(row5Action);
		turnList.add(row5Action);
		turnList.add(row6Action);
		
		for(int i = 0; i < turnList.size(); i++)
		{
			if(i % 2 == 0)
			{
				currPlayer = yellow;
			}
			else
			{
				currPlayer = red;
			}
			
			currAction = turnList.get(i);
			currAction.setPlayer(currPlayer);
			
			testState.doAction(currAction);
			System.out.println(testState.toString() + "\n" + testState.terminalTest());
		}
		
		
		System.out.println("Test 2 Ende!\n");
		
		/*System.out.println(testState.toString() + "\n" + testState.terminalTest(row7Action));
		
		testState.doAction(row3Action);
		
		System.out.println(testState.toString() + "\n" + testState.terminalTest(row7Action));*/
		
	}

}
